 var arr = [2,9,4,8,5,3,4,7];

 for (var j = 0;j < arr.length - 1;j++){
     for (var k = 0; k <arr.length - j -1;k++){
         if (arr[k] > arr[k + 1]){
             var num = arr[k];
             arr[k] = arr[k + 1];
             arr[k + 1] = num;

             console.log(arr);
         }
     }
 }